package org.mobile.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mobile.beans.Order;
import org.mobile.logic.OrderLogic;

/**
 * Servlet implementation class GetOrders
 */
@WebServlet(name = "getOrders", urlPatterns = { "/getOrders" })
public class GetOrders extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public GetOrders() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//if(request.getSession().getAttribute("orders") == null){   DKA: po zmianie statusu danego orderu nie pobiera nowego stanu 
			List<Order> orderList= OrderLogic.getInstance().getAllOrders();
			if(orderList != null){
				request.getSession().setAttribute("orders", orderList);
				
			}
			else{
				request.setAttribute("error", "Błąd wczytywania zamówień!");
				request.getRequestDispatcher("errPage.jsp").forward(request, response);
			}
				
		//}
		response.sendRedirect("transactions.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
